# Maintainer: Jerome Leclanche <jerome@leclan.ch>
# Maintainer: Maxim Baz <$pkgname at maximbaz dot com>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=prettier
pkgver=3.1.0
pkgrel=1
pkgdesc="An opinionated code formatter for JS, JSON, CSS, YAML and much more"
arch=("any")
url="https://prettier.io/"
license=("MIT")
depends=("nodejs")
makedepends=("git" "yarn")
checkdepends=("npm")
source=("git+https://github.com/$pkgname/$pkgname.git#tag=$pkgver")
b2sums=('SKIP')

prepare() {
    cd "$pkgname"
    yarn --frozen-lockfile
}

build() {
    cd "$pkgname"
    yarn build
}

check() {
    cd "$pkgname"
    yarn test:dist
}

package() {
    local mod_dir=/usr/lib/node_modules/$pkgname
    install -d "$pkgdir"/{usr/bin,usr/share/licenses/$pkgname,$mod_dir}
    ln -s "$mod_dir/bin/$pkgname.cjs" "$pkgdir/usr/bin/$pkgname"
    ln -s "$mod_dir/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

    cd "$pkgname"
    cp -a dist/* "$pkgdir"/$mod_dir
}
